import { Public } from '@/decorators/visit.decorator';
import { Body, Controller, Get, Post, Query, Req } from '@nestjs/common';
import {
  ApiBearerAuth,
  ApiOperation,
  ApiQuery,
  ApiTags,
} from '@nestjs/swagger';
import { CommentService } from './comment.service';
import { CommentDto } from './dto/comment.dto';
import { ReplyDto } from './dto/reply.dto';

@ApiTags('动态评论')
@Controller('comment')
export class CommentController {
  constructor(private readonly commentService: CommentService) {}

  @ApiOperation({
    summary: '增加一个评论',
  })
  @Post('/createComment')
  @ApiBearerAuth()
  createComment(@Req() req, @Body() commentDto: CommentDto) {
    return this.commentService.createComment({
      ...commentDto,
      commentUserId: req.user.id,
    });
  }

  @ApiOperation({
    summary: '增加一个回复',
  })
  @Post('/createReply')
  @ApiBearerAuth()
  createReply(@Req() req, @Body() replyDto: ReplyDto) {
    return this.commentService.createReply({
      ...replyDto,
      replyUserId: req.user.id,
    });
  }

  @Public()
  @ApiOperation({
    summary: '获取动态评论内容',
  })
  @Get('/getDynamicComment')
  @ApiQuery({
    name: 'dynamicId',
    description: '动态id',
    type: Number,
  })
  getDynamicComment(@Query('dynamicId') dynamicId: number) {
    return this.commentService.getDynamicComment(Number(dynamicId));
  }
}
